package pro.cherish.knowledgecmomon.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * @author 创建人：cherish
 * @version 版本号：V1.0
 * <p>
 * ***************************修订记录************************************
 * 2019-11-02 cherish 创建该类功能。
 * **********************************************************************
 * </p>
 * @ClassName 类名：PageResp
 * @Description 功能说明：
 * <p>
 * TODO
 * </p>
 * **********************************************************************
 * @date 创建日期： 2019-11-02 cherish
 */

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@ApiModel("通用分页响应")
public class PageResp<T> {

    @ApiModelProperty(value = "当前页码", required = true)
    private Integer current;

    @ApiModelProperty(value = "页面大小", required = true)
    private Integer size;

    @ApiModelProperty(value = "总数", required = true)
    private Integer total;

    @ApiModelProperty(value = "总页码", required = true)
    private Integer pages;

    @ApiModelProperty("记录")
    private List<T> rows;

    @ApiModelProperty("数据合计记录")
    private T footer;

    public Integer getPages() {
        if (size == null) {
            size = 10;
        }
        if (total == null) {
            total = 0;
        }
        return total % size == 0 ? (total / size) : (total / size + 1);
    }
}

